package network.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @author mubei
 * @date 2021/12/5
 * @description
 */
public class UDPServer_ {


    public static void main(String[] args) throws Exception {
        // 建立socket
        DatagramSocket socket = new DatagramSocket( 9999);

        // 接受数据包
        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes, 0, bytes.length);
        socket.receive(packet);

        System.out.println(new String(packet.getData(),0, packet.getLength()));
        // 关闭
        socket.close();
    }
}
